package com.Day1009;

import com.day0923.oop03.data.Data;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Text9 {
    public static void main(String[] args) throws IOException {
        //   https://img0.baidu.com/it/u=1275095085,1961143463&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800
        String urlStr = "https://img0.baidu.com/it/u=2642223955,2176778396&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500";
        //  JDK  网络类
        URL url = new URL(urlStr);
        URLConnection urlConnection = url.openConnection();
        InputStream inputStream = urlConnection.getInputStream();
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        byte[] temp = new byte[1024];
        File file = new File("F:\\Java\\风景.jpeg");
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);
        int len = -1;
        while ((len = dataInputStream.read()) != -1){
            dataOutputStream.write(temp,0,len);
            dataOutputStream.flush();

        }
        dataOutputStream.close();
        dataInputStream.close();
        fileOutputStream.close();
        inputStream.close();
    }
}
